<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$article22 = M("article") -> where("pid = 22 and flag = 'c'") -> order("time desc") -> limit(8) -> select();
    	$article23 = M("article") -> where("pid = 23 and flag = 'c'") -> order("time desc") -> limit(8) -> select();
    	$article24 = M("article") -> where("pid = 24 and flag = 'c'")  -> order("time desc") -> limit(8) -> select();
    	$article25 = M("article") -> where("pid = 25 and flag = 'c'")  -> order("time desc") -> limit(8) -> select();
    	//下载中心
    	$article16 = M("download") -> select();
    	//项目申报
        $where21["pid"] = array("in","26,27,28,29");
        $where21["flag"] = "c";
    	$article21 = M("article") -> where($where21)-> order("time desc") -> limit(8) -> select();
    	//政策法规
        $where18["pid"] = array("in","30,31,32,33");
        $where18["flag"] = "c";
    	$article18 = M("article") -> where($where18)-> order("time desc") -> limit(8) -> select();
        $server = M("category") -> where("pid = 6") -> limit(6) -> order("id desc") -> select();
        $this -> assign("server",$server);
        $article48 = M("article") -> where("pid = 48 and flag='c'") -> limit(8) -> select();
        //友情链接
        $friendLink = M("friendlink") -> select();
        $this -> assign("friendLink",$friendLink);
        $this -> assign("article48",$article48);
    	$this -> assign("article22",$article22);
    	$this -> assign("article23",$article23);
    	$this -> assign("article24",$article24);
    	$this -> assign("article25",$article25);
    	$this -> assign("article16",$article16);
    	$this -> assign("article21",$article21);
    	$this -> assign("article18",$article18);
        $this->display();
    }

    public function search(){
    	$search = htmlspecialchars(I('select'));
        $where['title'] = array("like","%{$search}%");
        $where['content'] = array("like","%{$search}%");
        $where['_logic'] = "OR";
    	$count = M('article') -> where($where) ->count();
    	$page = new \Think\Page($count,20);
    	$page -> setConfig('header',"<div class='subPage'>共%TOTAL_ROW%条</div>");
	$page -> setConfig('first','首页');
	$page -> setConfig('prev','上一页');
	$page -> setConfig('next','下一页');
	$page -> setConfig('link','indexpagenumb');//pagenumb 会替换成页码
	$page -> setConfig('theme',' %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
    	$show = $page -> show();
    	$article = M('article') -> where($where) -> limit($page -> firstRow.','.$page -> listRows) -> select();
    	$this -> assign('article',$article);
    	$this -> assign('page',$show);
    	$this -> display();
    }

    public function num(){
        $id = $_POST['num'];
        $clicks = M("article") -> field('click') -> where("id = {$id}") -> select();
		$info['click'] = $clicks[0]['click'] + 1;
		M("article") -> where("id = {$id}") -> save($info);
    }
}